<?php
include_once "vendor/autoload.php";
$tmp = new \PhpOffice\PhpWord\TemplateProcessor('tmp.docx');//打开模板
//1变量替换
$tmp->setValue('name', '李四');//替换变量name
$tmp->setValue('mobile', '18888888888');//替换变量mobile
//2复制行
$arr = [
    ['school' => '大学', 'year' => '2014'],
    ['school' => '大学', 'year' => '2014'],
    ['school' => '大学', 'year' => '2014'],
    ['school' => '大学', 'year' => '2014'],
    ['school' => '大学', 'year' => '2014'],
    ['school' => '大学', 'year' => '2014'],
    ['school' => '大学', 'year' => '2014'],
];
$rows = count($arr);//总行数
$tmp->cloneRow('school', $rows);//复制行
for ($i = 0; $i < $rows; $i++) {
    $tmp->setValue("school#" . ($i + 1), $arr[$i]['school']);//替换变量
    $tmp->setValue("year#" . ($i + 1), $arr[$i]['year']);
}

//3块操作
$winning_record = "";
if ($winning_record != '') {
    $tmp->cloneBlock('WIN_BLOCK', 1);
    $tmp->setValue('winning_record', $winning_record);
} else {
    #$tmp->deleteBlock('WIN_BLOCK');//这个方法会出错，原因不知，用cloneBlock来代替
    $tmp->cloneBlock('WIN_BLOCK', 0);
}

//图片
$tmp->setImageValue('header', ['path' => '1.jpg']);

// 设置图片宽高
$tmp->setImageValue('header', ['path' => '1.jpg','width'=>500,'height'=>500]);

// 设置多次替换
$tmp->setImageValue('header', ['path' => '1.jpg','width'=>500,'height'=>500],3);

$tmp->saveAs(time() . '_简历.docx');//另存为